<template>
  <div>
    <center align="center">
      <h1><span style="color: red">========#</span>司机抢单界面<span style="color: red">#========</span></h1>
    </center>


    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="订单编号" width="150">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.orderNumber }}</span>
        </template>
      </el-table-column>
      <el-table-column label="乘客电话" width="130">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.passengerPhone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="乘客下单时间" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.startTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="起点名称" width="280">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.startAddress }}</span>
        </template>
      </el-table-column>
      <el-table-column label="终点地址名称" width="280">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.endAddress }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="handleDelete(scope.row.orderNumber)">抢单</el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
//例如：import 《组件名称》 from '《组件路径》,
import {
  driverPreemptOrder,
  driverTakeOrder,
  preemptOrder,
  redissonDriverPreempt,
  selectAllByStatus,
  selectByDriverIdselectByCityCode
} from '@/api/driver/driver'
import { getInfo } from '@/api/login'

export default {
  //import引入的组件需要注入到对象中才能使用"
  components: {},
  props: {},
  data() {
    //这里存放数据"

    return {
      cityCode: 310000,
      tableData: [],
      requestPreempt: {
        orderNumber: '',
        driverId: 1
      }
    }
  },
  //计算属性 类似于data概念",
  computed: {},
  //监控data中的数据变化",
  watch: {},
  //方法集合",
  methods: {
    getInfo() {
      getInfo().then(res => {
        //console.log("登录人信息")
        //console.log(res)
        //this.requestPreempt.driverPhone=res.data.user.phonenumber
      })
    },
    handleDelete(orderNumber) {
      this.requestPreempt.orderNumber = orderNumber
      //console.log("请求参数")
      //console.log(this.requestPreempt)
      redissonDriverPreempt(this.requestPreempt).then(res => {
        //console.log("抢单结果")
        //console.log(res)
        alert('抢单成功')
        this.selectAllByStatus()
      })
    },
    selectAllByStatus() {
      selectAllByStatus().then(res => {
        //console.log("列表信息")
        //console.log(res)
        this.tableData = res.data
      })
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）",
  created() {
    this.getInfo()
    this.selectAllByStatus()
  },
  //生命周期 - 挂载完成（可以访问DOM元素）",
  mounted() {
  },
  beforeCreate() {
  }, //生命周期 - 创建之前",
  beforeMount() {
  }, //生命周期 - 挂载之前",
  beforeUpdate() {
  }, //生命周期 - 更新之前",
  updated() {
  }, //生命周期 - 更新之后",
  beforeDestroy() {
  }, //生命周期 - 销毁之前",
  destroyed() {
  }, //生命周期 - 销毁完成",
  activated() {
  } //如果页面有keep-alive缓存功能，这个函数会触发",
}
</script>
<style scoped>

</style>
